package signal;

import sun.dc.pr.PRError;
import sun.misc.SignalHandler;

public class SignalManager implements SignalHandler {

    private String TERM="TERM";
    private String INT="INT";

    /**
     * true=正常, false=退出
     */
    static volatile boolean status = true;

    @Override
    public void handle(sun.misc.Signal signal) {
        callback(signal);
    }

    private void callback(sun.misc.Signal signal){
        if (signal.getName().equals(TERM)||signal.getName().equals(INT)){
            //exit
            status=false;
            System.out.println(signal.getName()+" signal recevied");
            System.out.println("now stop all thread...");
        }
    }
}
